package cn.chenchendemospringboot.order_demo.controller;

import cn.chenchendemospringboot.order_demo.entity.KafkaEventPublish;
import cn.chenchendemospringboot.order_demo.entity.Order;
import cn.chenchendemospringboot.order_demo.service.KafkaEventPublishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/kafkaeventPublish")
public class KafkaEventPublishController {
    @Autowired
    KafkaEventPublishService kafkaEventPublishService;

    @PostMapping("/insert")
    public boolean createOrder(@RequestBody KafkaEventPublish kafkaEventPublish) {
        // 设置具体的字段值
        kafkaEventPublish.setEventType("Test");
        kafkaEventPublish.setPayload("test");
        kafkaEventPublish.setStatus("NEW");

        // 调用Service层的saveOrder方法
        return kafkaEventPublishService.save(kafkaEventPublish);
    }

    /**
     * 表单入参
     * @param status
     * @return
     */
    @GetMapping("/selectByContional")
    public List<KafkaEventPublish> selectByContional(@RequestParam(value = "status", required = false) String status) {
        // 调用Service层的saveOrder方法
        return kafkaEventPublishService.listByCondition(status);
    }

    /**
     * json 入参
     * @param kafkaEventPublish
     * @return
     */

    /**
     * 试错   表单入参
     * {
     *     "timestamp": "2025-01-14T07:33:41.551+00:00",
     *     "status": 400,
     *     "error": "Bad Request",
     *     "path": "/demo/kafkaeventPublish/selectByContional"
     * }
     * @param kafkaEventPublish
     * @return
     */
    @PostMapping("/selectByContional")
    public List<KafkaEventPublish> selectByContional(@RequestBody KafkaEventPublish kafkaEventPublish) {
        // 调用Service层的saveOrder方法
        return kafkaEventPublishService.listByCondition(kafkaEventPublish.getStatus());
    }
}
